import router from '@system.router';

export default {
    data: {
        options: {xAxis: {}, yAxis: {max: 160}},
        datasets: [{data: [], gradient: true}],
        maxmin: [
            {icon: "max", value: 0},
            {icon: "min", value: 0}],
        average: 0
    },
    rand(min, max) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    },
    maxminavg() {
       this.maxmin[0].value = Math.max.apply(null, this.datasets[0].data);
       this.maxmin[1].value = Math.min.apply(null, this.datasets[0].data);
       for (let i = 0; i < this.datasets[0].data.length; ++i)
           this.average += this.datasets[0].data[i];
       this.average = Math.round(this.average / this.datasets[0].data.length);
    },
    onInit() {
        for (let i = 0; i < 100; ++i)
            this.datasets[0].data.push(this.rand(73, 159));
        this.maxminavg();
    },
    onSwipe(e) {
        switch (e.direction) {
            case "left":
                router.replace({
                    uri: "pages/index/index"
                });
                break;

            case "bottom":
                router.replace({
                    uri: "pages/emotion/emotion"
                });
                break;

            case "top":
                router.replace({
                    uri: "pages/motion/motion"
                });
                break;
        }
    }
}
